<?php
/**
 * 支付
 *
 *
 *
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');

class member_paymentControl extends mobileMemberControl {

	public function __construct() {
		parent::__construct();
	}

    /**
     * 支付
     */
    public function payOp() {
	    $pay_sn = $_GET['pay_sn'];
        $payment_code = 'alipay';

        $model_payment = Model('payment');
        $result = $model_payment->productBuy($pay_sn, $payment_code, $this->member_info['member_id']);
        if(!empty($result['error'])) {
            output_error($result['error']);
        }
        //第三方API支付
        $this->_api_pay($result['order_pay_info'], $result['payment_info']);
    }

	/**
	 * 第三方在线支付接口
	 *
	 */
	private function _api_pay($order_pay_info, $payment_info) {
    	$inc_file = BASE_PATH.DS.'api'.DS.'payment'.DS.$payment_info['payment_code'].DS.$payment_info['payment_code'].'.php';
    	if(!file_exists($inc_file)){
            output_error('支付接口不存在');
    	}
    	require_once($inc_file);
        $param = array();
    	$param = unserialize($payment_info['payment_config']);
        $param['order_sn'] = $order_pay_info['pay_sn'];
        $param['order_amount'] = $order_pay_info['pay_amount'];
        $param['sign_type'] = 'MD5';
    	$payment_api = new $payment_info['payment_code']($param);
        $return = $payment_api->submit($param);
        echo $return;
    	exit;
	}

    /*
     * alpay接口入口
     *
     * */
    public function alipayapiOp(){
//        var_dump($_SESSION);exit;
        require_once("D:/www/zhaojinyin_b2c/mobile/api/payment/alipay/alipay.config.php");
        require_once("D:/www/zhaojinyin_b2c/mobile/api/payment/alipay/lib/alipay_submit.class.php");

        /**************************请求参数**************************/

        //商户订单号，商户网站订单系统中唯一订单号，必填
        //        $out_trade_no = $_POST['WIDout_trade_no'];
        $out_trade_no = $_GET['pay_sn'];
        //订单名称，必填
        //        $subject = $_POST['WIDsubject'];
        $subject = '金银商城余额充值';
        //付款金额，必填
        //        $total_fee = $_POST['WIDtotal_fee'];
        $total_fee = $_SESSION['pdr_amount'];
        //收银台页面上，商品展示的超链接，必填
        //        $show_url = $_POST['WIDshow_url'];
        $show_url = 'http://www.zhaojinyin.cn/mobile';
        //商品描述，可空
        //        $body = $_POST['WIDbody'];
        $body = '金银商城余额充值';


        /************************************************************/

        //构造要请求的参数数组，无需改动
        $parameter = array(
            "service"       => $alipay_config['service'],
            "partner"       => $alipay_config['partner'],
            "seller_id"  => $alipay_config['seller_id'],
            "payment_type"	=> $alipay_config['payment_type'],
            "notify_url"	=> $alipay_config['notify_url'],
            "return_url"	=> $alipay_config['return_url'],
            "_input_charset"	=> trim(strtolower($alipay_config['input_charset'])),
            "out_trade_no"	=> $out_trade_no,
            "subject"	=> $subject,
            "total_fee"	=> $total_fee,
            "show_url"	=> $show_url,
            "body"	=> $body,
            //其他业务参数根据在线开发文档，添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1
            //如"参数名"	=> "参数值"   注：上一个参数末尾需要“,”逗号。

        );

        //建立请求
        $alipaySubmit = new AlipaySubmit($alipay_config);
        $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认");
        echo $html_text;
    }
}
